/*
 * Player.cpp
 *
 *  Created on: 24.01.2011
 *      Author: JTH
 */
#include "Player.h"

Player::Player()
{
	nr = 0;
	lapCount = 0;
	lapTime = 0;
	fastestLapTime = 1000000;
	timeNow = 0;
	startTime = 0;
	slotsensor = false;
	racePosition = 0;
	fastestPlayer = false;
	playerstatus = STOP;
}

Player::Player(int pnr)
{
	nr = pnr;
	lapCount = 0;
	lapTime = 0;
	fastestLapTime = 1000000;
	timeNow = 0;
	startTime = 0;
	slotsensor = false;
	racePosition = 0;
	fastestPlayer = false;
	playerstatus = STOP;
}

void Player::ResetPlayer()
{
	lapCount = 0;
	lapTime = 0;
	timeNow = 0;
	startTime = 0;
	slotsensor = false;
	racePosition = 0;
	fastestPlayer = false;
	playerstatus = STOP;
	fastestLapTime = 1000000;
}

void Player::getPlayerStats(char* pStat, int displaytype)
{
	memset (pStat, 0, sizeof(pStat));
	char pnr[4], lt[8], flt[8], lc[4];
	memset (pnr, 0, 4);
	memset (lt, 0, 8);
	memset (flt, 0, 8);
	memset (lc, 0, 4);

	// Player, Laptime, fastestLaptime, lap count
	sprintf(pnr, "%1d", nr + 1);
	sprintf(lt, "%2lu.%03lu", lapTime/1000L, lapTime%1000L);
	sprintf(flt, "%2lu.%03lu", fastestLapTime/1000L, fastestLapTime%1000L);
	sprintf(lc, "%2d", lapCount);

	switch(displaytype)
	{
	case LCDDISPLAY:
		sprintf(pStat, "P%s %s %s L:%s", pnr, lt, flt, lc);
		break;
	//case FASTESTLAP:
	//	sprintf(pStat, "<< P%s: %s >>", pnr, flt);
	//	break;
	case DATA2PC:
		sprintf(pStat, "#P%s LT:%s FLT:%s LC:%s ", pnr, lt, flt, lc);
		break;
	}
	return;
}

bool Player::CheckForJumpStart()
{
	//todo: add jumpStart behavior
	if (playerstatus == JUMPSTART)
	{
		// e.g. stop powersupply for this player for 3 sec.
		return true;
	}
	return false;
}

